package com.zcg.gasmanager.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zcg.gasmanager.dao.LogDao;
import com.zcg.gasmanager.dao.PayDao;
import com.zcg.gasmanager.dao.impl.LogDaoImpl;
import com.zcg.gasmanager.dao.impl.PayDaoImpl;
import com.zcg.gasmanager.model.Log;
import com.zcg.gasmanager.model.User;
import com.zcg.gasmanager.service.PayService;
import com.zcg.gasmanager.utils.VeDate;

@Component("payService")
public class PayServiceImpl implements PayService {
	
	private PayDao payDao;
	private LogDao logDao;
	public PayDao getPayDao() {
		return payDao;
	}
	@Resource
	public void setPayDao(PayDao payDao) {
		this.payDao = payDao;
	}

	public LogDao getLogDao() {
		return logDao;
	}
	@Resource
	public void setLogDao(LogDao logDao) {
		this.logDao = logDao;
	}

	private Log log = new Log();
	
	/* (non-Javadoc)
	 * @see com.zcg.gasmanager.service.impl.PayService#update(com.zcg.gasmanager.model.User)
	 */
	@Override
	@Transactional
	public void add(User u){
		payDao.add(u);
		if(u.getId() == 0){
			log.setMsg(VeDate.getStringDate()+": update Gas error");
		}else{
			log.setMsg(VeDate.getStringDate()+": update Gas");
		}
		logDao.add(log);
	}
	
	/* (non-Javadoc)
	 * @see com.zcg.gasmanager.service.impl.PayService#queryAll()
	 */
	@Override
	@Transactional
	public List<User> queryAll(){
		List<User> users = payDao.queryAll();
		log.setMsg(VeDate.getStringDate()+": queryAll Gas");
		logDao.add(log);
		return users;
	}
}
